package game;

import java.awt.Color;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.Random;

import javax.swing.Action;
import javax.swing.JButton;

public class Cell extends JButton implements MouseListener{
	private boolean alive;
	private boolean liveToNextGeneration;
	
	private Random rnd = new Random();
	public Cell(Action al) {
		super(al);
		addMouseListener(this);
		setBackground(Color.WHITE);
	}
	
	public void setAlive(boolean alive) {
		this.alive = alive;
		if (alive) {
//			setBackground(new Color(rnd.nextInt(255), rnd.nextInt(255), rnd.nextInt(255)));
			setBackground(Color.RED);
		} else {
			setBackground(Color.WHITE);
		}
	}

	public boolean isAlive() {
		return alive;
	}

	@Override
	public void mouseClicked(MouseEvent arg0) {
		
	}

	@Override
	public void mouseEntered(MouseEvent me) {
		if (me.isControlDown()) {
			setAlive(!alive);
		}
	}

	@Override
	public void mouseExited(MouseEvent arg0) {
		
	}

	@Override
	public void mousePressed(MouseEvent arg0) {
		
	}

	@Override
	public void mouseReleased(MouseEvent arg0) {
		
	}

	public boolean isLiveToNextGeneration() {
		return liveToNextGeneration;
	}

	public void setLiveToNextGeneration(boolean liveToNextGeneration) {
		this.liveToNextGeneration = liveToNextGeneration;
	}

}
